<%-- 
    Document   : Search
    Created on : Dec 5, 2012, 11:03:16 AM
    Author     : Quang Thao
--%>

<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Search book</title>
        <%@include file="../LayoutAdmin/InHead.jsp" %>
    </head>
    <body>
        <div id="horizontal_bar">
            <div id="wrapper">
                <%@include file="../LayoutAdmin/Top.jsp" %>
                <div id="middle">
                    <%@include file="../LayoutAdmin/Middle_Top.jsp" %>
                    <div class="left">
                        <div class="menuitem_ulstyle_vertical">
                            <ul>
                                <li>
                                    <a href="Add.jsp">Thêm</a>
                                </li>
                                <li>
                                    <a href="Delete.jsp">Xóa</a>
                                </li>
                                <li>
                                    <a href="Search.jsp">Tra cứu</a>
                                </li>
                            </ul>
                        </div>
                    </div>
                    <div class="bar_bt_lr"></div>
                    <div class="right">
                        <form action="../../SearchBookServlet" method="POST">
                            <%
                                BO.Book_TypeBO btBO = new BO.Book_TypeBO();
                                List listType = btBO.GetAll();
                            %>
                            <h1>Tra cứu sách</h1>
                            <table class="Table3">
                                <tr>
                                    <td>Thể loại : </td>
                                    <td>
                                        <select name="cbxType">
                                            <option value="all">Tất cả</option>
                                            <%
                                                for (int i = 0; i < listType.size(); i++) {
                                                    Bean.Book_TypeBean bt = (Bean.Book_TypeBean) listType.get(i);
                                            %>
                                            <option value="<%= bt.getID()%>"><%= bt.getName()%></option>
                                            <%
                                                }
                                            %>
                                        </select>
                                    </td>
                                </tr>
                                <tr>
                                    <th colspan="2">
                                        <input type="submit" value="Tra cứu" name="btnFind" class="Button1" />
                                    </th>
                                </tr>
                            </table>
                            <table class="Table4">
                                <tr>
                                    <th>Hình ảnh</th>
                                    <th>ISBN</th>
                                    <th>Tên sách</th>
                                    <th>Thể loại</th>
                                    <th>Số lượng</th>
                                    <th>Giá</th>
                                </tr>
                                <%
                                    BO.BookBO bookBO = new BO.BookBO();
                                    List listBook = new ArrayList<Bean.BookBean>();

                                    if (request.getQueryString() != null) {
                                        String type = request.getQueryString().split("=")[1];
                                        if (type.equals("all")) {
                                            listBook = bookBO.GetAll();
                                        } else {
                                            listBook = bookBO.GetAll(type);
                                        }
                                    } else {
                                        listBook = bookBO.GetAll();
                                    }
                                    for (int i = 0; i < listBook.size(); i++) {
                                        Bean.BookBean bookTemp = (Bean.BookBean) listBook.get(i);

                                %>
                                <tr>
                                    <td>
                                        <img src="<% out.print("../../Content/Images/Book/" + bookTemp.getPicture());%>"/>
                                    </td>
                                    <td><%= bookTemp.getISBN()%></td>
                                    <td><%= bookTemp.getName()%></td>
                                    <td><%= bookTemp.getType().getName()%></td>
                                    <td><%= bookTemp.getQuantity()%></td>
                                    <td><%= String.format("%,4.0f VNĐ", bookTemp.getCost())%></td>
                                </tr>
                                <%
                                    }
                                %>
                            </table>
                        </form>
                    </div>
                </div>
                <%@include file="../LayoutUser/Bottom.jsp" %>
            </div>
        </div>
    </body>
</html>
